package liuds.music.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import liuds.music.R;
import liuds.music.model.Music;

/**
 * Created by Administrator on 2018/6/1.
 */

public class PlayMusicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    public List<Music> music;

    public PlayMusicAdapter(Context context, List<Music> music){
        this.context = context;
        this.music = music;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.play_music_item,parent,false);
        return new PlayMusicViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        PlayMusicViewHolder playMusicViewHolder = (PlayMusicViewHolder)holder;
        playMusicViewHolder.title.setText(music.get(position).getTitle());
        playMusicViewHolder.singer.setText(music.get(position).getSinger());
    }

    @Override
    public int getItemCount() {
        return music.size();
    }

    private class PlayMusicViewHolder extends RecyclerView.ViewHolder{

        private ImageView icon;
        private TextView title;
        private TextView singer;

        public PlayMusicViewHolder(View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.icon);
            title = itemView.findViewById(R.id.title);
            singer = itemView.findViewById(R.id.singer);
        }
    }
}
